package com.edu.modules.baseinfo.dao;

import com.edu.modules.baseinfo.model.Lesson;
import com.sari.common.persistence.BaseDao;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * Created by lab on 2016/7/15.
 */
@Repository
public class SignUpDao extends BaseDao {

	public int getCount(String studentId,String lessonId){

		String sql = "SELECT COUNT(*) FROM t_sign_up WHERE student_id  = ? and lesson_id = ?";

		return getCount(sql,studentId,lessonId);
	}

	public List getStudentIdByLessonId(String lessonId){

		String sql = "select lesson_id from t_sign_up where lesson_id = ?";

		return listBySql(sql,lessonId);
	}

	public List getSignUpList(String studentPhone,int isPaid,int offset,int limit){

		String sql = "select a.sign_up_id,b.lesson_name,b.lesson_class,b.teacher_name,c.student_name,c.phone,a.is_paid,a.create_time from t_sign_up a,t_lesson b,t_student c where " +
				"a.lesson_id = b.lesson_id and a.student_id = c.student_id ";
		if (!studentPhone.equals("")){
			sql += " and c.phone like '%"+studentPhone+"%'";
		}
		if(isPaid!=2){
			sql += " and a.is_paid = "+isPaid;
		}
		sql +=" ORDER BY a.create_time DESC limit ?,?";

		return listBySql(sql,offset,limit);
	}

	public int getSignUpCounts(String studentPhone,int isPaid){

		String sql = "select count(*) from t_sign_up a,t_lesson b,t_student c where a.lesson_id = b.lesson_id " +
				"and a.student_id = c.student_id";
		if (!studentPhone.equals("")){
			sql += " and phone = '"+studentPhone+"'";
		}
		if(isPaid!=2){
			sql += " and is_paid = "+isPaid;
		}

		return getCount(sql);
	}

	public int updatePaidStatus(String id,int isPaid,String payDate){

		String sql = "update t_sign_up set is_paid = ?,pay_date = ? where sign_up_id = ?";

		return saveOrUpdateOrDelete(sql,isPaid,payDate,id);
	}
}
